
namespace Crux.Core.Cache.Extensions;
/// <summary>
/// IHybridCacheProvider
/// </summary>
public interface IHybridCacheProvider
{
    /// <summary>
    /// 判断缓存值是否存在
    /// </summary>
    /// <param name="cacheKey">Key</param>
    /// <returns>是否存在</returns>
    bool Exists(string cacheKey);
    /// <summary>
    /// 判断缓存值是否存在
    /// </summary>
    /// <param name="cacheKey">Key</param>
    /// <param name="cancellationToken">cancellationToken</param>
    /// <returns>是否存在</returns>
    Task<bool> ExistsAsync(string cacheKey, CancellationToken cancellationToken = default);
    /// <summary>
    /// 获取指定缓存值
    /// </summary>
    /// <typeparam name="T">缓存具体类型</typeparam>
    /// <param name="cacheKey">key</param>
    /// <returns>缓存值</returns>
    T? Get<T>(string cacheKey);
    /// <summary>
    /// 获取指定缓存值
    /// </summary>
    /// <typeparam name="T">缓存具体类型</typeparam>
    /// <param name="cacheKey">key</param>
    /// <param name="cancellationToken">cancellationToken</param>
    /// <returns>缓存值</returns>
    Task<T?> GetAsync<T>(string cacheKey, CancellationToken cancellationToken = default);
    /// <summary>
    /// 获取指定缓存值，不存在的时候执行dataRetriever并重新进行缓存，内部使用分布式锁，避免重复操作分布式锁
    /// </summary>
    /// <typeparam name="T">缓存具体类型</typeparam>
    /// <param name="cacheKey">key</param>
    /// <param name="dataRetriever">获取具体值</param>
    /// <returns>缓存值</returns>
    T? GetOrCreate<T>(string cacheKey, Func<HybridCacheOption, T> dataRetriever);
    /// <summary>
    ///  获取指定缓存值，不存在的时候执行dataRetriever并重新进行缓存，内部使用分布式锁，避免重复操作分布式锁
    /// </summary>
    /// <typeparam name="T">缓存具体类型</typeparam>
    /// <param name="cacheKey">key</param>
    /// <param name="dataRetriever">获取具体值</param>
    /// <param name="cancellationToken">cancellationToken</param>
    /// <returns>缓存值</returns>
    Task<T?> GetOrCreateAsync<T>(string cacheKey, Func<HybridCacheOption, Task<T>> dataRetriever, CancellationToken cancellationToken = default);
    /// <summary>
    /// 移除相应缓存值
    /// </summary>
    /// <param name="cacheKey">key</param>
    void Remove(string cacheKey);
    /// <summary>
    /// 移除相应缓存值
    /// </summary>
    /// <param name="cacheKey">key</param>
    /// <param name="cancellationToken">cancellationToken</param>
    Task RemoveAsync(string cacheKey, CancellationToken cancellationToken = default);
    /// <summary>
    /// 尝试移除相应缓存值，并返回缓存值
    /// </summary>
    /// <typeparam name="T">缓存具体类型</typeparam>
    /// <param name="cacheKey">key</param>
    /// <param name="value">缓存值</param>
    /// <returns>是否移除成功</returns>
    bool TryRemove<T>(string cacheKey, out T? value);
    /// <summary>
    /// 设置缓存值
    /// </summary>
    /// <typeparam name="T">缓存具体类型</typeparam>
    /// <param name="cacheKey">key</param>
    /// <param name="cacheValue">需要缓存的值</param>
    /// <param name="expiration">有效期</param>
    void Set<T>(string cacheKey, T cacheValue, TimeSpan? expiration = null);
    /// <summary>
    /// 设置缓存值
    /// </summary>
    /// <param name="cacheKey">Cache key.</param>
    /// <param name="cacheValue">Cache value.</param>
    /// <param name="expiration">有效期</param>
    /// <param name="cancellationToken">cancellationToken</param>
    /// <typeparam name="T">缓存具体类型</typeparam>
    Task SetAsync<T>(string cacheKey, T cacheValue, TimeSpan? expiration = null, CancellationToken cancellationToken = default);
    /// <summary>
    /// 尝试设置值
    /// </summary>
    /// <typeparam name="T">缓存具体类型</typeparam>
    /// <param name="cacheKey">key</param>
    /// <param name="cacheValue">需要缓存的值</param>
    /// <param name="forceUpdate"></param>
    /// <param name="expiration">缓存值</param>
    /// <returns>是否设置成功</returns>
    bool TrySet<T>(string cacheKey, T cacheValue, bool forceUpdate = false, TimeSpan? expiration = null);
    /// <summary>
    /// 尝试设置值
    /// </summary>
    /// <typeparam name="T">缓存具体类型</typeparam>
    /// <param name="cacheKey">key</param>
    /// <param name="cacheValue">需要缓存的值</param>
    /// <param name="forceUpdate"></param>
    /// <param name="expiration">有效期</param>
    /// <param name="cancellationToken">cancellationToken</param>
    /// <returns>是否设置成功</returns>
    Task<bool> TrySetAsync<T>(string cacheKey, T cacheValue, bool forceUpdate = false, TimeSpan? expiration = null, CancellationToken cancellationToken = default);
}